package sg.edu.nus.iss.umpire;

import javax.servlet.http.HttpServlet;

@SuppressWarnings("serial")
public class DaoTestServlet extends HttpServlet {
//
//	public void doGet(HttpServletRequest request, HttpServletResponse response)
//			throws IOException {
//		EntityManager em = EMF.get().createEntityManager();
//		List<UmpireAssessment> uaList = null;
//		List<Umpire> list = null;
//		List<Competition> competitionList = null;
//		List<CompetitionDay> competitionDayList = null;
//		List<Session> sessionList = null;
//		response.setContentType("text/html");
//
//		response.getWriter().println("Test Page For DAO ");
//		response.getWriter().println("<BR></BR> ");
//
//		// Testing for DAO
//
//		// ***************** CompetitionDay Dao Start ****************/
//
//		/*
//		 * response.getWriter().println("Testing Competition day Insert ");
//		 * response.getWriter().println("<BR></BR> ");
//		 * 
//		 * 
//		 * // ###### Inserting CompetitionDay Data CompetitionDayDaoImpl
//		 * competitionDayDaoImpl = new CompetitionDayDaoImpl();
//		 * 
//		 * CompetitionDay competitionDay = new CompetitionDay();
//		 * competitionDay.setCompetitionName("ESPA"); competitionDay.setDate(new
//		 * Date());
//		 * 
//		 * competitionDay.setStartDate(new Date()); Calendar cal =
//		 * Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, 1);
//		 * competitionDay.setEndDate(cal.getTime());
//		 * 
//		 * competitionDay.setLocation("SRC");
//		 * competitionDay.setRefereeName("Mr Tom");
//		 * 
//		 * try { competitionDayDaoImpl.insertCompetitionDay(competitionDay); }
//		 * catch (Exception e) { // TODO Auto-generated catch block
//		 * e.printStackTrace(); }
//		 * 
//		 * response.getWriter().println(
//		 * "CompetitionDay Data Inserted successfully ");
//		 * response.getWriter().println("<BR></BR> ");
//		 * 
//		 * // ###### Setting Session Data Session session = new Session();
//		 * session.setSlot("AM");
//		 * session.setCompetitionDayKey(competitionDay.getCompetitionDayKey());
//		 * 
//		 * try { competitionDay =
//		 * competitionDayDaoImpl.findCompetitionDay("ESPA"); } catch (Exception
//		 * e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
//		 * 
//		 * sessionList = new ArrayList<Session>(); sessionList.add(session);
//		 * competitionDay.setSessions(sessionList);
//		 * 
//		 * //// ###### Binding Session to CompetitionDay Data
//		 * 
//		 * try { competitionDayDaoImpl.updateCompetitionDay(competitionDay); }
//		 * catch (Exception e) { // TODO Auto-generated catch block
//		 * e.printStackTrace(); }
//		 * 
//		 * response.getWriter().println(
//		 * "Binding Session to Competion Day is successful ");
//		 * response.getWriter().println("<BR></BR> ");
//		 * 
//		 * //// ###### Print the contents try { competitionDayList =
//		 * competitionDayDaoImpl.findAllCompetitionDay(); } catch (Exception e)
//		 * { // TODO Auto-generated catch block e.printStackTrace(); } for
//		 * (CompetitionDay day : competitionDayList) { sessionList =
//		 * day.getSessions(); response.getWriter().println("sessionList>>> " +
//		 * sessionList); if (null != sessionList) { for (Session s :
//		 * sessionList) response.getWriter().println("Session >>> " +
//		 * s.toString()); } }
//		 */
//		
//		// ***************** Session Dao Start ****************/
//		response.getWriter().println("Inserted CompetitionDay First to get Key Start ");
//		CompetitionDayDaoImpl competitionDayDaoImpl = new CompetitionDayDaoImpl(
//				em);
//		
//		CompetitionDay competitionDay=new CompetitionDay();
//		competitionDay.setDate("25/07/2013");
////		competitionDay.setCompetitionName("Test CompetitionDay");
////		competitionDay.setEndDate(new Date());
////		competitionDay.setStartDate(new Date());
////		competitionDay.setLocation("SRC");
////		competitionDay.setRefereeName("Mr Tom");
//		
//		try {
//			competitionDayDaoImpl.insert(competitionDay);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		response.getWriter().println("Inserted CompetitionDay First to get Key End ");
//		response.getWriter().println("<BR></BR> ");
//
//		response.getWriter().println("Getting CompetitionDayKey Start ");
//		try {
//			
//			competitionDayList = competitionDayDaoImpl.loadAll();
//			
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		response.getWriter().println("Getting CompetitionDayKey End ");
//		response.getWriter().println("<BR></BR> ");
//		response.getWriter().println("Testing competitionDaybyKey start ");
//		CompetitionDay competitionDayTest = null;
//		try {
//			competitionDayTest = competitionDayDaoImpl.getByKey(competitionDayList
//					.get(0).getCompetitionDayKey());
//		} catch (Exception e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}
////		response.getWriter().println("competitionDayTest== " + competitionDayTest.getRefereeName());
//		response.getWriter().println("Testing competitionDaybyKey end ");
//		response.getWriter().println("<BR></BR> ");
//
//		response.getWriter().println("Testing Session Insert ");
//		SessionDaoImpl sessionDaoImpl = new SessionDaoImpl(em);
//				
//		Session session=new Session();
//		session.setSlotName("AM");
//		session.setCompetitionDayKey(competitionDayList.get(0).getCompetitionDayKey());
//	
//		try {
//			sessionDaoImpl.insert(session);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//
//		response.getWriter().println("Session Inserted successfully ");
//		response.getWriter().println("<BR></BR> ");
//		
//		response.getWriter().println("Testing Session Update ");
//		response.getWriter().println("<BR></BR> ");
//
//		try {
//			session.setSlotName("PM");
//			sessionDaoImpl.update(session);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		response.getWriter().println("Session Data Updated successfully ");
//		response.getWriter().println("<BR></BR> ");
//	
//		
//		/*
//		 * response.getWriter().println("Testing findAllSession  "); try {
//		 * 
//		 * sessionList=sessionDaoImpl.findAllSession();
//		 * 
//		 * } catch (Exception e) { // TODO Auto-generated catch block
//		 * e.printStackTrace(); } response.getWriter().println(
//		 * "Session List found completed successfully with "
//		 * +sessionList.size()+" records");
//		 * response.getWriter().println("<BR></BR> ");
//		 */
//		
//		
//		response.getWriter().println("Testing findSessionByCompetitionDay  ");
//		try {
//			
//			sessionList=sessionDaoImpl.findSessionByCompetitionDay(competitionDayList.get(0));
//			
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		response.getWriter().println("findSessionByCompetitionDay Session List found completed successfully with "+sessionList.size()+" records");
//		response.getWriter().println("<BR></BR> ");
//		response.getWriter().println("Testing findSessionbyKey start ");
//		Session sessionTest = null;
//		try {
//			sessionTest = sessionDaoImpl.getByKey(sessionList.get(0).getSessionKey());
//		} catch (Exception e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}
//		response.getWriter().println("findSessionbyKey== " + sessionTest.getSlotName());
//		response.getWriter().println("Testing findSessionbyKey end ");
//		response.getWriter().println("<BR></BR> ");
//		
//		response.getWriter().println("Testing AddSessionToCmpetition");
//		competitionDayDaoImpl.addSession(competitionDayList.get(0), sessionList.get(0));
//		List<Session> sessionListTest =competitionDayDaoImpl.listSession(competitionDayList.get(0));
//		if(sessionListTest != null){
//			response.getWriter().println("getSessionList=="+sessionListTest.size()+" records");
//			response.getWriter().println("<BR></BR> ");
//		}
//		
//		//insert umpire to test getUmpireList
//		response.getWriter().println("Testing Umpire Insert ");
//		Umpire umpire = new Umpire();
//		umpire.setNric("NewTest");
//		umpire.setName("Umpire2");
//		umpire.setAddress("Location SRN");
//		UmpireDAOImpl umpireDao = new UmpireDAOImpl(em);
//		List<Umpire> umpireList = new ArrayList<Umpire>();
//		try {
//			umpireDao.insert(umpire);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		response.getWriter().println("Umpire Data Inserted successfully ");
//		//end insert umpire
//		try {
//
//			umpireList = umpireDao.loadAll();
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		response.getWriter().println("Testing AddConfirmedUmpire To Session");
//		sessionDaoImpl.addConfirmedUmpireToSession(sessionList.get(0),umpireList.get(0));
//		List<Umpire> confirmedUmpireList =sessionDaoImpl.getConfirmedUmpireListBySession(sessionList.get(0));
//		if(confirmedUmpireList != null){
//			response.getWriter().println("confirmedUmpireList=== "+confirmedUmpireList.size()+" records");
//			response.getWriter().println("<BR></BR> ");
//		}
//		
//	/*	response.getWriter().println("Testing AddAvailUmpire To Session");
//		sessionDaoImpl.addAvailUmpireToSession(sessionList.get(0),list.get(0));
//		List<Umpire> availUmpireList =sessionDaoImpl.getAvailUmpireListBySession(sessionList.get(0));
//		if(availUmpireList != null){
//			response.getWriter().println("availUmpireList=== "+availUmpireList.size()+" records");
//			response.getWriter().println("<BR></BR> ");
//		}*/
//		
//		response.getWriter().println("Testing Session Delete ");
//		try {
//			for(Session sessionTemp:sessionList ){
//				sessionDaoImpl.deleteByKey(sessionTemp.getSessionKey());
//			}
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		response.getWriter().println("Session Data Deleted successfully ");
//		response.getWriter().println("<BR></BR> ");
//		
//		response.getWriter().println("CompetitionDay Delete ");
//		try {
//			for(CompetitionDay competitionDayTemp:competitionDayList ){
//				//TODO
//				//				competitionDayDaoImpl.deleteByKey(competitionDayTemp
////						.getCompetitionKey());
//			}
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		response.getWriter().println("CompetitionDay Data Deleted successfully ");
//		response.getWriter().println("<BR></BR> ");
//		
//		response.getWriter().println("Umpire Delete ");
//		try {
//			for(Umpire umpireTemp:umpireList ){
//				umpireDao.deleteByKey(umpireTemp.getKey());
//			}
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		response.getWriter().println("Umpire Deleted successfully ");
//		response.getWriter().println("<BR></BR> ");
//		// ***************** Session Dao End ****************/
//
//	}
}
